﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PloobsEngine.SceneControl;
using PloobsEngine.Physics;
using PloobsEngine.Modelo;
using PloobsEngine.Material;
using PloobsEngine.Engine;
using PloobsEngine.Light;
using PloobsEngine.Physics.Bepu;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
using PloobsEngine.Cameras;
using PloobsEngine.Input;
using PloobsEngine.Entity;
using PloobsEngine.MessageSystem;

namespace PloobsProjectTemplate
{
    class Camera : CameraFollowObject
    {
        public XWing xWing;

        public Quaternion cameraRotation = Quaternion.Identity;

        public Camera(IObject obj, Vector3 forward):base(obj, forward)
        {
            xWing = (XWing)(obj);
            this.FarPlane = 3000F;
            this.NearPlane = 1f;
        }

        protected override void Update(GameTime gt)
        {
            cameraRotation = Quaternion.Lerp(cameraRotation, xWing.xWingRotation, 0.1f);

            Vector3 campos = new Vector3(0, 2f, -13f);
            campos = Vector3.Transform(campos, Matrix.CreateFromQuaternion(cameraRotation));
            //campos = Vector3.Transform(campos, xWing.PhysicObject.Rotation);
            campos += xWing.PhysicObject.Position;

            //this.YAlwaysUp = true;
            Vector3 camup = new Vector3(0, 1, 0);
            camup = Vector3.Transform(camup, Matrix.CreateFromQuaternion(cameraRotation));

            this.Rotation = Quaternion.CreateFromRotationMatrix(xWing.PhysicObject.Rotation);
            this.Position = campos;
            this.Target = xWing.PhysicObject.Position;
            this.Up = camup;
           
        }

        
    }
}
